﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Licenta1.Statements
{
    class CommandParams:Statement
    {
        string cmd;
        Expression Params;

        public CommandParams(Context context, string cmdName, Expression expr)
            : base(context)
        {
            cmd = cmdName;   
            Params = expr;
        }

        //to REDO.
        public override void Execute()
        {
            switch ( cmd )
            {
                case "display": Display((ArrayList)Params.Value); break;
                default: Console.WriteLine("Command " + cmd + " object: " + Params.Value); break;
            }
        }

        public void Display(ArrayList list)
        {
            foreach (Expression e in list)
            {
                if (e != null && list.IndexOf(e) == 0)
                    Console.WriteLine("\n" + e.Value);
                else if (e != null && list.IndexOf(e) == 1)
                {
                    list.RemoveAt(0);
                    Display(list);
                }
            }
                
        }
    }
}
